package com.shareach.http.sys.rpc;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shareach.dao.redis.impl.SnatchRDao;
import com.shareach.http.sys.parameter.CheckSnatchParameter;
import com.shareach.web.basic.Answer;
import com.shareach.web.basic.Ask;
import com.shareach.web.basic.IAskRPC;
@Service("checkSnatchUrlRPC")
public class CheckSnatchUrlRpc implements IAskRPC {
	@Autowired
	private SnatchRDao snatchRDao;

	@Override
	public Answer<?> run(Ask ask, String ip) throws Exception {
		CheckSnatchParameter p = getParameterMap(ask);
		Answer<?> result = getAnswer();
		if(snatchRDao.isSnatchedSiteUrl(p.city, p.site, p.url)){
			result.setMsg("已经采集");
			result.setCode( -2);//
		}
		
		return result;
	}

	@Override
	public Answer<?> getAnswer() {
		return new Answer<Object>();
	}

	@Override
	public CheckSnatchParameter getParameterMap(Ask ask) {
		CheckSnatchParameter parameter = new CheckSnatchParameter();
		HashMap<String,Object> map = ask.getRequest();
		parameter.parseFromMap(map);
		return parameter;
	}
}
